rm(list=ls())

setwd("~/Dropbox/Immigration/Analysis/Gravity Models/")

library(haven)
library(dplyr)
library(ggplot2)
library(corrgram)
library(corrplot)
library(RColorBrewer)

data <- read_dta('corrgram_gravity.dta')

names(data) <- c("Forced Migrant Arrival Rate", "Policy Index (5 Yr. MA)", "Access Index (5 Yr. MA)", "Services Index (5 Yr. MA)", "Livelihoods Index (5 Yr. MA)", "Movement Index (5 Yr. MA)", "Participation Index (5 Yr. MA)", "High Mobile Penetration in CoO", "High Information Openness in CoO", "Transnational Ethnic Kin", "Inter-capital Distance", "Territorial Contiguity", "Common Language", "Bilateral Migrant Stock", "African Dyad", "Middle Eastern Dyad", "South Asian Dyad", "Population in CoO", "Population in CoA", "GDP/Capita Ratio", "GDP/Capita Ratio Squared", "Unemployment Rate in CoO", "Unemployment Rate in CoA", "Civil War in CoO", "Civil War in CoA", "Repression in CoO", "Repression in CoA")

newdata <- na.omit(data)

corrdata <- cor(newdata)

head(round(corrdata,3))

par( ps=9)

corrplot(corrdata, method="circle", col=brewer.pal(n=6, name="RdYlBu"), tl.col="black", tl.cex = .6, tl.srt=90, bg="gray96")

dev.copy(png,'corrgram_gravity.png', width = 7, height = 7, units = 'in', res = 300)
dev.off()